package com.cosfly.sharemusic.user.controller;

import com.cosfly.sharemusic.entity.Result;
import com.cosfly.sharemusic.user.dto.LoginDto;
import com.cosfly.sharemusic.user.dto.PasswordDto;
import com.cosfly.sharemusic.user.dto.UserDto;
import com.cosfly.sharemusic.user.dto.UserResult;
import com.cosfly.sharemusic.user.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
@Api(value = "用户管理")
public class UserController {
    @Autowired
    private UserService userService;

    @PostMapping("/register")
    @ApiOperation(value = "用户注册")
    @ResponseBody
    public Result register(@ApiParam(value = "用户注册信息" , required=true )UserDto userDto){
        Result result = new Result();
        result = userService.register(userDto);   //用户注册
        return result;
    }

    @PostMapping("/addimage")
    @ApiOperation(value = "用户添加头像")
    @ResponseBody
    public Result addImage(@ApiParam(value = "用户唯一编号",required = true)@RequestParam(name="userCode") String userCode,
                           @ApiParam(value = "用户头像base64字符串",required = true)@RequestParam(name="userImage") String userImage){
        Result result = new Result();
        result = userService.addImage(userCode,userImage);   //用户添加头像
        return result;
    }

    @PostMapping("/login")
    @ApiOperation(value = "用户登录")
    @ResponseBody
    public UserResult login(@ApiParam(value = "用户登录信息" , required=true )LoginDto loginDto){
        UserResult result = new UserResult();
        result = userService.login(loginDto);
        return result;
    }

    @PostMapping("/modifypassword")
    @ApiOperation(value = "用户修改密码")
    @ResponseBody
    public Result modifyPassword(@ApiParam(value = "用户新密码信息",required = true)PasswordDto passDto){
        Result result = new Result();
        result = userService.modifyPassword(passDto);
        return result;
    }

    @PostMapping("/out")
    @ApiOperation(value="用户登出")
    @ResponseBody
    public Result out(@ApiParam(value="用户编号",required = true)@RequestParam(name = "userCode")String userCode){
        Result result = new Result();
        result = userService.out(userCode);
        return result;
    }

    @PostMapping("/logout")
    @ApiOperation(value="用户注销")
    @ResponseBody
    public Result logOut(@ApiParam(value="用户编号",required = true)@RequestParam(name = "userCode")String userCode){
        Result result = new Result();
        result = userService.logOut(userCode);
        return result;
    }
}
